package com.example.mall.web.controller;

import com.example.mall.domain.OrderExceptions;
import com.example.mall.dto.OrderExceptionsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.OrderExceptionsQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IOrderExceptionsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orderExceptions")
public class OrderExceptionsController {

    @Autowired
    public IOrderExceptionsService orderExceptionsService;

    /**
     * 分页查询订单异常处理表信息
     * @param orderExceptionsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询订单异常处理表信息",notes = "分页查询订单异常处理表信息",httpMethod = "GET")
    public JSONResult queryPage(OrderExceptionsQuery orderExceptionsQuery){
        PageDTO<OrderExceptionsDto> orderExceptionsDtoPageDTO = orderExceptionsService.queryPage(orderExceptionsQuery);
        return JSONResult.success("查询成功",orderExceptionsDtoPageDTO);
    }

    /**
     * 根据id查询订单异常处理表信息
     * @param exceptionId
     * @return
     */
    @GetMapping("query/{exceptionId}")
    @ApiOperation(value = "根据id查询订单异常处理表信息",notes = "根据id查询订单异常处理表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("exceptionId")Long exceptionId){
        //1.根据id查询用户信息
        if (exceptionId == null){
            throw new GlobalCustomerException(ErrorEnumCode.EXCEPTIONID_NOT_ID);
        }
        OrderExceptions orderExceptions = orderExceptionsService.getById(exceptionId);
        return JSONResult.success("查询成功",orderExceptions);
    }

    /**
     * 根据id查询订单异常处理表信息
     * @param exceptionId
     * @return
     */
    @GetMapping("queryOrderExceptionsById/{exceptionId}")
    @ApiOperation(value = "根据id查询订单异常处理表信息",notes = "根据id查询订单异常处理表信息",httpMethod = "GET")
    public JSONResult queryOrderExceptionsById(@PathVariable("exceptionId")Long exceptionId){
        //1.根据id查询用户信息
        if (exceptionId == null){
            throw new GlobalCustomerException(ErrorEnumCode.EXCEPTIONID_NOT_ID);
        }
        OrderExceptions orderExceptions = orderExceptionsService.queryOrderExceptionsById(exceptionId);
        return JSONResult.success("查询成功",orderExceptions);
    }

    /**
     * 查询全部订单异常处理表信息
     * @param
     * @return
     */
    @GetMapping("queryOrderExceptionsList")
    @ApiOperation(value = "查询全部订单异常处理表信息",notes = "查询全部订单异常处理表信息",httpMethod = "GET")
    public JSONResult queryOrderExceptionsList(){
        List<OrderExceptions> logins = orderExceptionsService.queryOrderExceptionsList();
        return JSONResult.success("查询成功",logins);
    }

    /**
     * 新增订单异常处理表
     * @param orderExceptionsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增订单异常处理表",notes = "新增订单异常处理表",httpMethod = "POST")
    public JSONResult insert(@RequestBody OrderExceptionsDto orderExceptionsDto){
        orderExceptionsService.insert(orderExceptionsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改订单异常处理表信息
     * @param orderExceptionsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改订单异常处理表信息",notes = "修改订单异常处理表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody OrderExceptionsDto orderExceptionsDto){
        orderExceptionsService.update(orderExceptionsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除订单异常处理表信息
     * @param exceptionId
     * @return
     */
    @PostMapping("delete/{exceptionId}")
    @ApiOperation(value = "删除订单异常处理表信息",notes = "删除订单异常处理表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("exceptionId") Long exceptionId) {
        orderExceptionsService.delete(exceptionId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除订单异常处理表信息
     * @param exceptionIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除订单异常处理表信息",notes = "批量删除订单异常处理表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> exceptionIds) {
        orderExceptionsService.deleteBatch(exceptionIds);
        return JSONResult.success("批量删除成功");
    }
}
